package com.geektime.hello;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class StringDemo {
    public static void main(String[] args) {
        String s = "1,2,3,4,";
        String ss = s.substring(0, s.length() - 1);
        System.out.println(ss);

//        String s1 = "https://ahtvoss.oss-cn-heyuan.aliyuncs.com/ahtvoss/20200917/450304ca-4876-12e4-5230-1f9540ba6e78.png";
//        String index = "ahtvoss.oss-cn-heyuan.aliyuncs.com";
        String s1 = "http://ahtv-obs.obs.cn-north-4.myhuaweicloud.com/20200927214031/44b13b8fc2344c82847c65afb9beb0e6.mp4";
        String index = "ahtv-obs.obs.cn-north-4.myhuaweicloud.com";
        int beginIndex = s1.indexOf(index) + index.length();
        String s11 = s1.substring(beginIndex);
        System.out.println(s11);
        String s12 = s1.substring(beginIndex, s1.lastIndexOf("/"));
        System.out.println(s12);

        index = index.replace("a", "b");
        System.out.println("index = " + index);


        String matTranscodeUrl = "[{\"clarity\":\"超清\",\"url\":\"http://obs.cn-north-4.myhuaweicloud.com/ahtv-obs-sobey/u-2x49025gw566w530/2020/12/16/390c05e805de4cac98dd12900707d2be_videogroup_eb8aa8c80c0b495183596a701.mp4\"},{\"clarity\":\"高清\",\"url\":\"http://obs.cn-north-4.myhuaweicloud.com/ahtv-obs-sobey/u-2x49025gw566w530/2020/12/16/390c05e805de4cac98dd12900707d2be_videogroup_eb8aa8c80c0b495183596a701.mp4\"},{\"clarity\":\"标清\",\"url\":\"http://obs.cn-north-4.myhuaweicloud.com/ahtv-obs-sobey/u-2x49025gw566w530/2020/12/16/390c05e805de4cac98dd12900707d2be_videogroup_eb8aa8c80c0b495183596a701.mp4\"}]";
        JSONArray urlArr = JSON.parseArray(matTranscodeUrl);
        for (Object object : urlArr) {
            JSONObject jsonObject = JSON.parseObject(object.toString());
            String url = jsonObject.getString("url");
            String newUrl = "ahahaha";
            matTranscodeUrl = matTranscodeUrl.replace(url, newUrl);
        }
        System.out.println("matTranscodeUrl = " + matTranscodeUrl);
    }
}
